package com.lemner.ke.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.lemner.ke.R;
import com.lemner.ke.base.BaseActivity;
import com.lemner.ke.base.SuccessListener;
import com.lemner.ke.model.library.ReportModel;
import com.lemner.ke.util.CacheManager;
import com.lemner.ke.util.SpUtils;
import com.lemner.ke.view.MyDialog;

import es.dmoral.toasty.Toasty;

/**
 * 作者：张恺 raintea
 * <p>
 * 时间：2018/9/18
 * <p>
 * 类描述：设置-页面
 */


public class SettingActivity extends BaseActivity {
    private Button btn_log_off;
    private LinearLayout accountSecutity;
    private LinearLayout settingMessage;
    private LinearLayout settingCache;
    private LinearLayout settingabout;
    private LinearLayout applicationScoring;

    @Override
    public int getLayoutFile() {
        return R.layout.activity_setting;
    }

    @Override
    public void initView() {
        btn_log_off = findViewById(R.id.btn_setting_log_off);
        accountSecutity = findViewById(R.id.ll_setting_account_secutity);
        settingMessage = findViewById(R.id.ll_setting_message);
        settingCache=findViewById(R.id.ll_setting_cache);
        settingabout=findViewById(R.id.ll_setting_about);
    }

    @Override
    public void initEvent() {
        btn_log_off.setOnClickListener(this);
        accountSecutity.setOnClickListener(this);
        settingMessage.setOnClickListener(this);
        settingCache.setOnClickListener(this);
        settingabout.setOnClickListener(this);
    }

    @Override
    public void initData() {

    }

    @Override
    protected void initSetting() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_setting_log_off:
                SpUtils.putString(SettingActivity.this, SpUtils.USERIDS, "");
                SpUtils.putString(SettingActivity.this, SpUtils.MOBILE_PHOE, "");
                SpUtils.putInt(SettingActivity.this, SpUtils.LOGIN_STATUS, SpUtils.UNLOGIN);
                startActivity(LoginActivity.class);
                finish();
                break;
            case R.id.ll_setting_account_secutity:  //账号与安全
                startActivity(AccountSecurityActivity.class);
                break;
            case R.id.ll_setting_message://新消息设置
                startActivity(MessageActivity.class);
                break;
            case R.id.ll_setting_cache:

                final MyDialog myDialog=new MyDialog(getContext(),"确认清空缓存吗");
                myDialog.show();
                myDialog.setOnConfirmClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if(CacheManager.cleanInternalCache(SettingActivity.this)){
                            Toasty.success(SettingActivity.this, "清空成功！", Toast.LENGTH_SHORT, true).show();
                        }else{
                            Toasty.error(SettingActivity.this, "清空失败！", Toast.LENGTH_SHORT, true).show();
                        }
                        myDialog.dismiss();
                    }
                });
                break;
            case R.id.ll_setting_about:
                startActivity(AboutActivity.class);
                break;
            default:
        }
    }
}
